<?php

namespace common\models;

use Yii;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Orders;

/**
 * OrdersSearch represents the model behind the search form about `common\models\Orders`.
 */
class OrdersSearch extends Orders
{
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['o_id', 'g_id', 'c_id'], 'integer'],
            [['o_num', 'o_total', 'o_status'], 'number'],
            [['add_data', 'beiyong', 'beiyong2'], 'safe'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function scenarios()
    {
        // bypass scenarios() implementation in the parent class
        return Model::scenarios();
    }

    /**
     * Creates data provider instance with search query applied
     *
     * @param array $params
     *
     * @return ActiveDataProvider
     */
    public function search($params)
    {
        $query = Orders::find();

        $dataProvider = new ActiveDataProvider([
            'query' => $query,
        ]);

        $this->load($params);

        if (!$this->validate()) {
            // uncomment the following line if you do not want to return any records when validation fails
            // $query->where('0=1');
            return $dataProvider;
        }

        $query->andFilterWhere([
            'o_id' => $this->o_id,
            'g_id' => $this->g_id,
            'c_id' => $this->c_id,
            'o_num' => $this->o_num,
            'o_total' => $this->o_total,
            'add_data' => $this->add_data,
            'o_status' => $this->o_status,
        ]);

        $query->andFilterWhere(['like', 'beiyong', $this->beiyong])
            ->andFilterWhere(['like', 'beiyong2', $this->beiyong2]);

        return $dataProvider;
    }
}
